<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
	
    <a-spin :spinning="confirmLoading">
		
		
		
		<a-table
		
		:columns="columns"
		 :data-source="data"
		
		>
		<!--   <template #name="{text}">
		     <a>{{ text }}</a>
		   </template> -->
		 </a-table>
		
      <a-form :form="form">


		<a-form-item
		      :labelCol="labelCol"
		      :wrapperCol="wrapperCol"
		      label="备注"
		      hasFeedback >
		     <a-textarea placeholder="请输入备注"v-model="remark" rows="8" style="float: left;"  disabled="disabled"/>
		    </a-form-item>
			
			
<a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <!-- <j-image-upload class="avatar-uploader" text="上传" v-model="fileList" style="margin-top: 8px;"></j-image-upload> -->
                  <!-- <el-upload
  style="margin-top: 20px;"
  action="http://clound_clothing.wenkangkeji.com/mlcc/user/interface/uploadImage"
  list-type="picture-card"
  :limit="1"
  :on-exceed="handleExceed"
  :on-preview="handlePictureCardPreview"
  :on-remove="handleRemove"
  :on-success="handleSuccess"
  ref="upload">
  <i class="el-icon-plus"></i>
</el-upload> -->
             凭证
            <j-image-upload class="avatar-uploader" text="上传" v-model="fileList" style="margin-top: 8px;"></j-image-upload>
       
                </a-form-item>
 
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
	const columns = [
	  {
	    title: '序号',
	            dataIndex: '',
	            key: 'rowIndex',
	            width: 60,
	            align: "center",
	            customRender: function (t, r, index) {
	              return parseInt(index) + 1;
	            }
	  },
	  {
	    title: '产品编号',
	    dataIndex: 'goodsCode',
	  
	    width: 80,
	  },
	  {
	    title: '供应商产品编号',
	    dataIndex: 'supplierGoodsCode',
	   
	    width: 80,
	  },
	  {
	    title: '差异类型',
	    dataIndex: 'differentTypes',
	   
	    ellipsis: true,
	  },
		{
		  title: '差异数量',
		  dataIndex: 'dealNumber',
		
		  ellipsis: true,
		},
	  {
	    title: '单价',
	    dataIndex: 'intoUnit',
	  
	    ellipsis: true,
	  },
	{
	  title: '差异金额',
	  dataIndex: 'differencesMoney',
	
	  ellipsis: true,
	},
		
	];
	
	
	const data = [
	  
	];
  import { httpAction,getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
 import JImageUpload from '../../../components/jeecg/JImageUpload'
  export default {
    name: "SeechayichuliDetail",
     components: {
      JImageUpload
    },
    data () {
      return {
		  data,
		  columns,
		  remark:'',
		  id:'',
		  remainingInventoryId:'',
		  merchandiseInventoryId:'',
		  intoUnit:'',
		  differentTypeId:'',
		  chayitypeList:[],
		  newCount:"",
         fileList: [],
        goodsId:'',
        pingzheng:'',
        userId:'',
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          add: "/Chayi/applychayichuli",
          edit: "/Chayi/applychayichuli",
		  chayitypelist:"/Chayi/getAlldifferentType",
		  detail:"/Chayi/getchayidetail"
        },
      }
    },
    created () {
		this.getallchayitype();
	
    },
    methods: {
		
		
	
		getchayidetail(){
			getAction(this.url.detail,{id:this.id}).then((res)=>{
			   if (res.success) {
					   this.remainingInventoryId=res.result.remainingInventoryId;

			       this.fileList=res.result.uploadDocuments;
				      this.remark=res.result.remark;
				   this.data = res.result.projectlist;
			       } else {
			         that.$message.warning(res.message);
			       }
			     });
		},
		
		
		//查询差异类型
		getallchayitype(){
			getAction(this.url.chayitypelist).then((res)=>{
			   if (res.success) {
			       this.chayitypeList=res.result;
			   this.xiangqingdetail.realname=realname;
			       } else {
			         that.$message.warning(res.message);
			       }
			     });
		},
		
       //上传图片成功函数
      handleSuccess(response, file, fileList) {
        var result = response;
        this.pingzheng = result.data;
      },
      add () {
        this.edit({});
      },
      edit (record) {
		    this.goodsId=record.goodsId;
		     this.merchandiseInventoryId=record.merchandiseInventoryId;
		  		    this.id=record.id;
		  	this.getchayidetail();
		  this.intoUnit=record.intoUnit;
        this.newCount=record.newCount;
        this.form.resetFields();
        // this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'name','keyWord','sex','age','email','content'))
		      //时间格式化
          this.form.setFieldsValue({punchTime:this.model.punchTime?moment(this.model.punchTime,'YYYY-MM-DD HH:mm:ss'):null})
          this.form.setFieldsValue({birthday:this.model.birthday?moment(this.model.birthday):null})
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);

            //时间格式化
            formData.punchTime = formData.punchTime?formData.punchTime.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.birthday = formData.birthday?formData.birthday.format():null;
            formData['differentTypeId']=this.differentTypeId;
            formData['intoUnit']=this.intoUnit;
			  formData['dealNumber']= this.data[0].dealNumber;
			  formData['id']=this.id;
			  formData['remainingInventoryId']=this.remainingInventoryId;
			
             formData['uploadDocuments']=this.fileList;
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('aaa');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style scoped>

</style>